package com.koron.common.core.util;

import com.koron.bean.base.BaseBean;
import com.koron.bean.system.staff.vo.EamUser;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @author jkw
 * 处理新增/修改工具类
 */
public class DisposeBeanUtil {
    private DisposeBeanUtil() {
    }

    /**
     * 新增处理
     * @param user
     * @param bean
     */
    public static void disposeInsert(EamUser user, BaseBean bean) {
        if (user == null || StringUtils.isAnyEmpty(user.getAccount(),user.getName())) {
            user = new EamUser();
            user.setName("test");
            user.setAccount("test");
        }
        bean.setId(CodeTools.getCode32());
        bean.setCreateBy(user.getAccount());
        bean.setCreateByName(user.getName());
        bean.setDeleteFlag(0);
        Date date = new Date();
        bean.setCreateTime(date);
    }

    /**
     * 修改处理
     * @param user
     * @param bean
     */
    public static void disposeUpdate(EamUser user, BaseBean bean) {
        if (user == null || StringUtils.isAnyEmpty(user.getAccount(),user.getName())) {
            user = new EamUser();
            user.setName("test");
            user.setAccount("test");
        }
        bean.setUpdateBy(user.getAccount());
        bean.setUpdateByName(user.getName());
        bean.setUpdateTime(new Date());
    }

    public static void dispose(EamUser user, BaseBean bean) {
        if (StringUtils.isBlank(bean.getId())) {
            disposeInsert(user, bean);
        }
        disposeUpdate(user, bean);
    }
}
